<?php
include_once (S_ROOT . './source/api_class.php');

class Login
{
    private $apiurl;
    private $apis;
    private $action;
    private $start = 0;
    private $length = 50;
    
    public function __construct($apiurl) {
        $this->apiurl   = $apiurl;
        $this->apis     = array(
            'userLogin'
        );
    }
    
    public function execute ($action) {
        if (!in_array($action, $this->apis)) {
            return render('login', request());
        }
        
        $this->action = $action;
        $result = $this->$action(request());
        return $result;
    }
  
    private function userLogin($req) {
        
        if (strlen($req['username']) < 1 || strlen($req['password']) < 1) {
            return false;
        }
        
        $account = isMobile($req['username']) ? "86-".trim($req['username']) : trim($req['username']);
        $passwd  = md5(trim($req['password']));
        
        $client = new FFapiClient ( null );
        $result = $client->getAccessToken ( $account, $passwd);
        if (empty($result)) return false;
        
        return true;
    }
}


$req = request();
$login   = new Login($_SC ['apiurl']);
echo $login->execute($req['op']);

